#pragma once

#include <QWidget>
namespace Ui { class CwgVTKModel; };
#include <vtkRenderer.h>
#include <vtkGenericOpenGLRenderWindow.h>
#include <QVector3D>
#include <QMap>
#include <vtkPoints.h>
#include <VTKCellType.h>
#include <vtkPolyData.h>
#include <vtkUnstructuredGrid.h>
#include <vtkEventQtSlotConnect.h>
#include <vtkPropPicker.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkProperty.h>
#include <vtkOrientationMarkerWidget.h>
//#include <>
//#include <>

struct stPointXYZ
{
	int nID;
	double x,y,z;
};

enum en_CellType{Point=0,Line, Surface, Solid};

class CwgVTKModel : public QWidget
{
	Q_OBJECT

public:
	CwgVTKModel(QWidget *parent = Q_NULLPTR);
	~CwgVTKModel();

public:
	void SetPointsXYZ(const QMap<int, QVector3D>& mapPoints);
	void SetCells(en_CellType cellType, const QMap<int, QVector<int>>& mapCells);  // for Line, Surface, and Solid
	void PlotCellsOn(en_CellType cellType, bool bOn = true);
	void PlotCellsLabelOn(en_CellType cellType, bool bOn = true);

	void Set3DAxesOn(bool bOn=true);
	void SetVTKReplot(bool bResetCamera = true);



private:
	Ui::CwgVTKModel *ui;

	void initVTK();  // 
	void init3DAxes();
	void initActors();  // 

	//void drawCells(en_CellType nType);
	void CalCellsLabel(en_CellType n);// n=0,point; n=1, lines; n=2, Planes; n=3, Vols

public slots:
	void onLeftButtonPressEvent(vtkObject* obj);


private:
	vtkSmartPointer<vtkRenderer> m_render{ nullptr };
	vtkSmartPointer<vtkGenericOpenGLRenderWindow> m_renWin{ nullptr };
	vtkSmartPointer<vtkEventQtSlotConnect> Connections{ nullptr };
	vtkSmartPointer<vtkOrientationMarkerWidget> m_widgetAxes{ nullptr };

	vtkSmartPointer<vtkPoints> m_vtkPoints{ nullptr };
	QList<vtkSmartPointer<vtkActor>> m_listActor;	// 0 -> Points, 1 -> Lines, 2 -> Surface, 3 -> Solids,
	QList<vtkSmartPointer<vtkActor2D>> m_listActor2D;	// 0 -> Points, 1 -> Lines, 2 -> Surface, 3 -> Solids,


	vtkSmartPointer<vtkActor> m_actorPicker{ nullptr };





	QMap<int, vtkIdType> m_mapPointsID;  // ptID -> vtkID


	QMap<int, QVector<int>> m_mapCellLines;  // CellID -> (pt1,pt2,pt3,pt4...)
	QMap<int, vtkIdType> m_mapCellLinesID;  // ptID -> vtkID
	QMap<int, QVector<int>> m_mapCellSurfaces;
	QMap<int, vtkIdType> m_mapCellSurfacesID;  // ptID -> vtkID
	QMap<int, QVector<int>> m_mapCellSolids;
	QMap<int, vtkIdType> m_mapCellSolidsID;  // ptID -> vtkID


	QMap<int, VTKCellType> m_mapVTKSolidCellType;// solid vertex number  -> CellType

public:
};
